package comlile.string;

public class _06StringReplace {

	public static void main(String[] args) {
		/*
		 * 替换功能 
		 * String replace(char old,char new) 
		 * String replace(String old,String new)
		 */
		// 定义字符串
		String s = "helloworld";

		String s2 = s.replace('l', 'b');
		System.out.println("s:" + s);
		System.out.println("s2:" + s2);

		String s3 = s.replace("owo", "ak47");
		System.out.println("s3:" + s3);

		// 去除字符串两空格 String trim()
		String ss = "     hello  world           ";

		System.out.println("---" + ss + "---");
		System.out.println("---" + ss.trim() + "---");

		// 按字典顺序比较两个字符串 a-z
		// int compareTo(String str)
		// int compareToIgnoreCase(String str)
		String sss = "hello";

		System.out.println(sss.compareTo("hello")); // 0
		System.out.println(sss.compareTo("Hello")); // 32
		System.out.println(sss.compareTo("mello")); // -5
		System.out.println(sss.compareTo("hgllo"));// 第一个不同字母之差

	}

}
